<template>
	<view style="font-size: 14px; background-color: #FFFFFF;">

		<view class="" style="width: 90%;margin-left: 5%;">
			<uni-search-bar placeholder="搜索" @input="search" clearButton="none" @cancel="quxiao"></uni-search-bar>
		</view>
		<view class="" style="display: flex;justify-content: space-around;align-items: center;margin-top: 10px;"> 
			<view class="">
				<view class="">
					<text>当前积分：</text>
					<text>{{jifen}}</text>
				</view>
				<view v-show="yonghuming!=''">
					<text>当前用户：</text>
					<text>{{yonghuming}}</text>
				</view>
			</view>
			
			<text class="xiugai" @click="subshuju">确认修改</text>
		</view>
		<view  style="margin-top: 20px;display: flex;justify-content: space-between;" v-for="(item,index) in list" :key="index" @click="yonghu(item)">
			<view class="" style="display: flex;align-items: center;">
				<image style="width: 50px;height: 50px;border-radius: 50%;margin-left: 10px;" :src="item.avatar" mode=""></image>
				<view class="" style="margin-left: 15px;">
					<text>{{item.nickname}}</text>
					<br>
					<text style="color: #8C8C8C;">{{item.integral}}分</text>
				</view>
			</view>
			<view v-show="uid ==item.uid">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<text style="color: #8C8C8C;margin-right: 10px;">上分</text><input type="number" value="" maxlength="5" placeholder="输入分数" v-model="sf" style="width: 100px;"/>
				</view>
				<view style="display: flex;flex-direction: row;align-items: center;">
						<text style="color: #8C8C8C;margin-right: 10px;">下分</text><input type="number" value="" maxlength="5"  placeholder="输入分数" v-model="xf" style="width: 100px;"/>
				</view>
			</view>
		</view>
			
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				list:[],
				sf:'',
				xf:'',
				jifen:0,
				yonghuming:'',
				uid:'',
				roomid:'',
				qid:''
				
			}
		},
		onLoad(options){ 
			this.roomid = options.roomid
			this.qid = options.qid
			console.log(options.roomid)
			let token = uni.getStorageSync('token')
			uni.request({
				url: this.G_base + '/api/lz/quserf',
				method: 'POST',
				header: { 
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				data: {
					id: options.roomid,
				},
				success: res => {
					console.log(res)
					this.list = res.data.data
				}
			})
			
		},
		methods: {
			yonghu(msg){
				console.log(msg)
				this.jifen = msg.integral
				this.yonghuming = msg.nickname
				this.uid = msg.uid
			},
			search(e){
				console.log(e.value)
				this.list.map(item=>{
					if(item.nickname.indexOf(e.value)!=-1){
						console.log(item)
						let arr = []
						arr.push(item)
						this.list=arr
					}
				})
				
			},
			quxiao(){
					let token = uni.getStorageSync('token')
					uni.request({
						url: this.G_base + '/api/lz/quserf',
						method: 'POST',
						header: { 
							'content-type': 'application/x-www-form-urlencoded',
							'Authori-zation': 'Bearer ' + token
						},
						data: {
							id: this.roomid,
						},
						success: res => {
							console.log(res)
							this.list = res.data.data
						}
					})
			},
			subshuju(){
				let that = this
				if(that.uid==''){
					uni.showToast({
						title:"请选择用户",
						icon:"none"
					})
					return
				}
				let token = uni.getStorageSync("token")
				uni.request({
					url: that.G_base + '/api/lz/qxgf',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data:{
						uid:that.uid,
						sf:that.sf,
						xf:that.xf,
						id:that.roomid
					},
					success: res => {
						console.log(res)
						uni.showToast({
							title:res.data.msg,
							icon:"none"
						})
						that.sf=''
						that.xf=''
						let token = uni.getStorageSync("token")
						uni.request({
							url: that.G_base + '/api/lz/quserf',
							method: 'POST',
							header: {
								'content-type': 'application/x-www-form-urlencoded',
								'Authori-zation': 'Bearer ' + token
							},
							data:{
								id:that.roomid,
							},
							success: res => {
								console.log(res)
								that.list = res.data.data
							}
						})
					}
				})
			}
		},
	}
</script>

<style scoped>
	.xiugai{
		width: 100px;
		height: 30px;
		/* margin: 150upx auto; */
		background: -webkit-linear-gradient(left, #a00000, #e10004, #a00000);
		border-radius: 40px;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;
	}
</style>
